using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace WindowsGame
{
    /// <summary>
    /// Draws the animation by the class itself.
    /// </summary>
    public class AnimatedMapObject : MapObject
    {
        #region Private fields

        /// <summary>
        /// Holds the animation of this object
        /// </summary>
        private AnimatedSprite mAnimatedSprite;

        /// <summary>
        /// Holds the bounds of this object
        /// </summary>
        private TileRect mBounds;

        #endregion

        #region Public properties

        /// <summary>
        /// Gets and sets the texture of this object
        /// </summary>
        public AnimatedSprite Animation
        {
            get
            {
                return this.mAnimatedSprite;
            }
            set
            {
                if (this.mAnimatedSprite != value)
                {
                    this.mAnimatedSprite = value;
                }
            }
        }

        /// <summary>
        /// Gets and sets the coordinates of this object
        /// </summary>
        public override TileRect Bounds
        {
            get
            {
                return this.mBounds;
            }
            set
            {
                if (this.mBounds != value)
                {
                    this.mBounds = value;
                }
            }
        }

        #endregion

        #region Public methods

        /// <summary>
        /// Draws the texture on the given position.
        /// </summary>
        /// <param name="batch">SpriteBatch object which uses this draw method to perform the drawing itself.</param>
        public override void Draw(SpriteBatch batch)
        {
            this.mAnimatedSprite.Draw(batch, new Vector2(this.mBounds.X + Global.Offset.X, this.mBounds.Y + Global.Offset.Y), Color.White);
        }

        /// <summary>
        /// Draws the texture on the given position.
        /// </summary>
        /// <param name="batch">SpriteBatch object which uses this draw method to perform the drawing itself.</param>
        /// <param name="alphaColor">Color to use for alpha blending.</param>
        public override void Draw(SpriteBatch batch, Color alphaColor)
        {
            this.mAnimatedSprite.Draw(batch, new Vector2(this.mBounds.X + Global.Offset.X, this.mBounds.Y + Global.Offset.Y), alphaColor);
        }

        /// <summary>
        /// Draws the animation by the class itself.
        /// </summary>
        /// <param name="elapsedTime">Elapsed time since last animation.</param>
        public void performUpdate(float elapsedTime)
        {
            if (this.mAnimatedSprite != null)
            {
                this.mAnimatedSprite.Update(elapsedTime);
            }
        }

        #endregion

        #region Constructor / Destructor

        /// <summary>
        /// Creates a new static map object.
        /// </summary>
        public AnimatedMapObject()
        {
            this.mAnimatedSprite = null;
        }

        /// <summary>
        /// Creates a new static map object.
        /// </summary>
        /// <param name="texture">Texture to draw.</param>
        public AnimatedMapObject(AnimatedSprite animatedSprite)
        {
            this.mAnimatedSprite = animatedSprite;
        }

        #endregion
    }
}
